package com.android.library.image;

import android.content.Context;

import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool;
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory;
import com.bumptech.glide.load.engine.cache.LruResourceCache;
import com.bumptech.glide.module.AppGlideModule;
import com.bumptech.glide.request.RequestOptions;

/**
 * @author xiaoxing
 * Created by pengsheng-2 on 2018/10/26.
 */

@GlideModule
public class MyAppGlideModule extends AppGlideModule {
    private static final int MAX_HEAP_SIZE = (int) Runtime.getRuntime().maxMemory();
    private static final int MAX_CACHE_MEMORY_SIZE = MAX_HEAP_SIZE / 4;
    private static final int MAX_CACHE_DISK_SIZE = 500 * 1024 * 1024;

    public final static String TAG = "MyAppGlideModule";


    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
        builder.setDiskCache(new InternalCacheDiskCacheFactory(context, MAX_CACHE_DISK_SIZE));
        builder.setMemoryCache(new LruResourceCache(MAX_CACHE_MEMORY_SIZE));
        builder.setBitmapPool(new LruBitmapPool(MAX_CACHE_MEMORY_SIZE));
        builder.setDefaultRequestOptions(
                new RequestOptions()
                        .format(DecodeFormat.PREFER_ARGB_8888)
                        .disallowHardwareConfig());
    }

}
